package math2;

/**
 * Lagrange basis function on 4-node tetrahedra
 * 
 * @author hbui
 * 
 */
public class LagrangeFBOnTet4 extends PolynomialBasisOnRnToR {

	public LagrangeFBOnTet4() {

		addBasisFunction(
		/*
		 * N1 = 1 - xi1 - xi2 - xi3
		 */
		new FunctionRnToR() {

			@Override
			public double valueAt(double... xi) {
				return 1 - xi[0] - xi[1] - xi[2];
			}

			@Override
			public double[] gradientAt(double... xi) {
				return new double[] { -1, -1, -1 };
			}
		},
		/*
		 * N2 = xi1
		 */
		new FunctionRnToR() {

			@Override
			public double valueAt(double... xi) {
				return xi[0];
			}

			@Override
			public double[] gradientAt(double... xi) {
				return new double[] { 1, 0, 0 };
			}
		},
		/*
		 * N3 = xi2
		 */
		new FunctionRnToR() {

			@Override
			public double valueAt(double... xi) {
				return xi[1];
			}

			@Override
			public double[] gradientAt(double... xi) {
				return new double[] { 0, 1, 0 };
			}
		},
		/*
		 * N4 = xi3
		 */
		new FunctionRnToR() {

			@Override
			public double valueAt(double... xi) {
				return xi[2];
			}

			@Override
			public double[] gradientAt(double... xi) {
				return new double[] { 0, 0, 1 };
			}
		});
	}

	@Override
	public int getP() {
		return 1;
	}

	@Override
	public void setP(int p) {
	}

	@Override
	public Object clone() {
		return new LagrangeFBOnTet4();
	}
}
